package dashboard;
import java.io.IOException;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.*;
	
@SuppressWarnings("serial")
public class LoginServlet extends HttpServlet {
	
	private LoginController LC;
	
	public void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws IOException, ServletException {
    
	LC = new LoginController();
	
    String username = req.getParameter("username");
    String password = req.getParameter("password");
    
    HttpSession session = req.getSession();
   
    
    
    session.setAttribute("Lusername", username);
    
    if(LC.checkUser(username, password))
    {	
    	Date now = new Date();
    	User cUser = UserRegistry.getInstance().getUser(username);
    	session.setAttribute("user", UserRegistry.getInstance().getUser(username));
    	resp.sendRedirect("dashboard.jsp?I=logged");
    	cUser.setPreviousLastLogin(cUser.getLastLogin());
        cUser.setLastLogin(now);
   
    	
	}
    else
    {	
    	resp.sendRedirect("login.jsp?l=false");
    }
	}
}
